package cn.jietuo.first.cartoonalgorithm;

/**
 * @author zhangx & jietuo_zx@163.com
 * @version 1.0
 * @date 2020/7/30
 * @description:
 */
public class StringTest {

    public static void main(String[] args) {
        test1();
        test2();
        test3();
        test4();
        test5();
        test6();
        test7();
        test8();
        test9();
    }

    public static void test1() {
        String str1 = "abcd";
        String str3 = "ab" + "cd";
        System.out.println("true:" + (str1 == str3));
        String str4 = "ab";
        str4 += "cd";
        System.out.println("false:" + (str1 == str4));
    }

    public static void test2() {
        String S1 = "abc";
        final String S2 = "a";
        final String S3 = "bc";
        String S4 = S2 + S3;
        System.out.println("true:" + (S1 == S4));
    }

    public static void test3() {
        String s1 = "abc";
        String s2 = "a";
        String s3 = "bc";
        String s4 = s2 + s3;
        System.out.println("false:" + (s1 == s4));
    }

    public static void test4() {
        String str3 = new String("str01");
        str3.intern();
        String str4 = "str01";
        System.out.println("false:" + (str3 == str4));
    }

    public static void test5() {
        String str2 = new String("str") + new String("01");
        String str1 = "str01";
        String str3 = str2.intern();
        System.out.println("true:" + (str3 == str1));
    }

    public static void test6() {
        String str2 = new String("str") + new String("01");
        str2.intern();
        String str1 = "str01";
        System.out.println("false:" + (str2 == str1));
    }

    public static void test7() {
        String str2 = new String("str") + new String("01");
        String str1 = "str01";
        str2.intern();
        System.out.println("false:" + (str2 == str1));
    }

    public static void test8() {
        String h = new String("cc");
        String intern = h.intern();
        System.out.println("false:" + (intern == h));
    }

    public static void test9() {
        final String str1 = "abc";
        final String str2 = "d";
        String str3 = str1.concat(str2);
        String str4 = str1 + str2;
        String str5 = "ab" + "cd";
        System.out.println(str3 == str4);
        System.out.println(str3 == str5);
        System.out.println(str4 == str5);

    }
}
